package com.fr.report;

import com.fr.base.FCloneable;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.report.core.PackedReport;
import com.fr.report.io.ReportExportAttr;
import com.fr.report.io.xml.ReportXMLUtils;
import com.fr.report.io.xml.SynchronizedStyleList;
import com.fr.report.io.xml.SynchronizedVersion;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public abstract class AbstractFineBook extends AbstractTableDataSource
  implements FineBook
{
  private List nameReportList = new ArrayList(1);
  protected ReportWebAttr reportWebAttr = null;
  protected ReportExportAttr reportExportAttr = null;

  protected void addReport(Report paramReport)
  {
    addReport(null, paramReport);
  }

  protected void addReport(String paramString, Report paramReport)
  {
    addReport(getReportCount(), paramString, paramReport);
  }

  protected void addReport(int paramInt, Report paramReport)
  {
    addReport(paramInt, null, paramReport);
  }

  protected abstract void setWorkBook(Report paramReport, FineBook paramFineBook);

  protected void addReport(int paramInt, String paramString, Report paramReport)
  {
    if (paramString == null)
      paramString = __autoReportName();
    this.nameReportList.add(paramInt, new NameReport(paramString, paramReport, null));
    setWorkBook(paramReport, this);
  }

  private NameReport __getNameReportByIndex(int paramInt)
  {
    return ((NameReport)this.nameReportList.get(paramInt));
  }

  public String getReportName(int paramInt)
  {
    return NameReport.access$100(__getNameReportByIndex(paramInt));
  }

  public void setReportName(int paramInt, String paramString)
  {
    NameReport.access$102(__getNameReportByIndex(paramInt), paramString);
  }

  public Report getReport(int paramInt)
  {
    return NameReport.access$200(__getNameReportByIndex(paramInt));
  }

  protected void setReport(int paramInt, Report paramReport)
  {
    setWorkBook(paramReport, this);
    NameReport.access$202(__getNameReportByIndex(paramInt), paramReport);
  }

  protected void setReport(int paramInt, String paramString, Report paramReport)
  {
    setWorkBook(paramReport, this);
    NameReport.access$102(__getNameReportByIndex(paramInt), paramString);
    NameReport.access$202(__getNameReportByIndex(paramInt), paramReport);
  }

  protected int getReportIndex(Report paramReport)
  {
    int i = 0;
    int j = this.nameReportList.size();
    while (i < j)
    {
      if (NameReport.access$200((NameReport)this.nameReportList.get(i)) == paramReport)
        return i;
      ++i;
    }
    return -1;
  }

  public void removeReport(String paramString)
  {
    int i = 0;
    int j = this.nameReportList.size();
    while (i < j)
    {
      NameReport localNameReport = __getNameReportByIndex(i);
      if (ComparatorUtils.equals(paramString, NameReport.access$100(localNameReport)))
      {
        setWorkBook(NameReport.access$200(localNameReport), null);
        this.nameReportList.remove(i);
        return;
      }
      ++i;
    }
  }

  public void removeReports()
  {
    int i = 0;
    int j = this.nameReportList.size();
    while (i < j)
    {
      setWorkBook(NameReport.access$200(__getNameReportByIndex(i)), null);
      ++i;
    }
    this.nameReportList.clear();
  }

  public void removeReport(int paramInt)
  {
    NameReport localNameReport = (NameReport)this.nameReportList.remove(paramInt);
    setWorkBook(NameReport.access$200(localNameReport), null);
  }

  public int getReportCount()
  {
    return this.nameReportList.size();
  }

  public ReportWebAttr getReportWebAttr()
  {
    return this.reportWebAttr;
  }

  public void setReportWebAttr(ReportWebAttr paramReportWebAttr)
  {
    this.reportWebAttr = paramReportWebAttr;
  }

  public void setReportExportAttr(ReportExportAttr paramReportExportAttr)
  {
    this.reportExportAttr = paramReportExportAttr;
  }

  public ReportExportAttr getReportExportAttr()
  {
    return this.reportExportAttr;
  }

  public PageSetChain generateReportPageSet(List paramList)
  {
    PageSet[] arrayOfPageSet = new PageSet[getReportCount()];
    for (int i = 0; i < arrayOfPageSet.length; ++i)
      arrayOfPageSet[i] = getReport(i).generateReportPageSet((paramList == null) ? null : (PaperSetting)paramList.get(i));
    return new PageSetChain(arrayOfPageSet);
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    AbstractFineBook localAbstractFineBook = (AbstractFineBook)super.clone();
    ArrayList localArrayList = new ArrayList();
    int i = 0;
    int j = this.nameReportList.size();
    while (i < j)
    {
      NameReport localNameReport = (NameReport)((NameReport)this.nameReportList.get(i)).clone();
      setWorkBook(NameReport.access$200(localNameReport), localAbstractFineBook);
      localArrayList.add(localNameReport);
      ++i;
    }
    localAbstractFineBook.nameReportList = localArrayList;
    if (getReportWebAttr() != null)
      localAbstractFineBook.setReportWebAttr((ReportWebAttr)getReportWebAttr().clone());
    if (getReportExportAttr() != null)
      localAbstractFineBook.setReportExportAttr((ReportExportAttr)getReportExportAttr().clone());
    return localAbstractFineBook;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    ReportWebAttr localReportWebAttr = getReportWebAttr();
    if (localReportWebAttr != null)
    {
      paramXMLPrintWriter.startTAG("ReportWebAttr");
      localReportWebAttr.writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
    }
    ReportExportAttr localReportExportAttr = getReportExportAttr();
    if (localReportExportAttr != null)
      localReportExportAttr.writeXML(paramXMLPrintWriter);
    int i = getReportCount();
    for (int j = 0; j < i; ++j)
    {
      Report localReport = getReport(j);
      if (localReport == null)
        break label125:
      String str = localReport.getClass().getName();
      paramXMLPrintWriter.startTAG("Report").attr("class", str).attr("name", getReportName(j));
      localReport.writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
    }
    label125:
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1;
      Object localObject;
      String str2 = paramXMLableReader.getTagName();
      if (str2.equals("Version"))
      {
        if ((str1 = paramXMLableReader.getElementValue()) != null)
        {
          localObject = SynchronizedVersion.getSynchronizedVersion(Thread.currentThread());
          ((SynchronizedVersion)localObject).setVersion(Double.parseDouble(str1));
        }
      }
      else if (str2.equals("XMLVersion"))
      {
        if ((str1 = paramXMLableReader.getElementValue()) != null)
        {
          localObject = SynchronizedVersion.getSynchronizedVersion(Thread.currentThread());
          ((SynchronizedVersion)localObject).setXmlVersionByString(str1);
        }
      }
      else if (("StyleList".equals(str2)) || ("CellStyleList".equals(str2)))
      {
        localObject = SynchronizedStyleList.getSynchronizedStyleList(Thread.currentThread());
        paramXMLableReader.readXMLObject(new XMLReadable(this, (SynchronizedStyleList)localObject)
        {
          private final SynchronizedStyleList val$synchronizedStyleList;
          private final AbstractFineBook this$0;

          public void readXML()
          {
            if (paramXMLableReader.isChildNode())
            {
              String str = paramXMLableReader.getTagName();
              if (("Style".equals(str)) || ("CellStyle".equals(str)))
                this.val$synchronizedStyleList.addStyle(ReportXMLUtils.readFullStyle(paramXMLableReader));
            }
          }
        });
      }
      else if ("Report".equals(str2))
      {
        localObject = null;
        if ((str1 = paramXMLableReader.getAttr("class")) != null)
          localObject = ReportXMLUtils.readReportFromClassName(str1);
        if ((!(SynchronizedVersion.isAfterREPORT_REFECT_FOR65_2_XML_VERSION())) && (this instanceof ResultWorkBook) && (localObject instanceof WorkSheet))
          localObject = new RWorkSheet();
        String str3 = "";
        if ((str1 = paramXMLableReader.getAttr("title")) != null)
          str3 = str1;
        if ((str1 = paramXMLableReader.getAttr("name")) != null)
          str3 = str1;
        if (localObject instanceof PackedReport)
        {
          paramXMLableReader.readXMLObject((XMLReadable)localObject);
          addReport(str3, (Report)localObject);
        }
        else
        {
          addReport(str3, (Report)localObject);
          paramXMLableReader.readXMLObject((XMLReadable)localObject);
        }
      }
      else if ("ReportWebAttr".equals(str2))
      {
        localObject = getReportWebAttr();
        if (localObject == null)
        {
          localObject = new ReportWebAttr();
          setReportWebAttr((ReportWebAttr)localObject);
        }
        paramXMLableReader.readXMLObject((XMLReadable)localObject);
      }
      else if ("ReportExportAttr".equals(str2))
      {
        localObject = new ReportExportAttr();
        paramXMLableReader.readXMLObject((XMLReadable)localObject);
        setReportExportAttr((ReportExportAttr)localObject);
      }
    }
  }

  private String __autoReportName()
  {
    Object localObject = "sheet1";
    int i = 0;
    int j = this.nameReportList.size();
    while (i < j)
    {
      String str1 = NameReport.access$100(__getNameReportByIndex(i));
      if (str1.toLowerCase().matches("^sheet[1-9]\\d*$"))
      {
        String str2 = "sheet" + (Integer.parseInt(str1.toLowerCase().substring(5)) + 1);
        if ((i == getReportCount() - 1) || (!(containsIgnoreCase(str2))))
        {
          localObject = str2;
          break;
        }
      }
      ++i;
    }
    return ((String)localObject);
  }

  private boolean containsIgnoreCase(String paramString)
  {
    int i = 0;
    int j = this.nameReportList.size();
    while (i < j)
    {
      String str = NameReport.access$100(__getNameReportByIndex(i));
      if (str.equalsIgnoreCase(paramString))
        return true;
      ++i;
    }
    return false;
  }

  private static class NameReport
    implements Cloneable, Serializable
  {
    private static final long serialVersionUID = -4090072956249660275L;
    private String name;
    private Report report;

    private NameReport(String paramString, Report paramReport)
    {
      this.name = paramString;
      this.report = paramReport;
    }

    public Object clone()
      throws CloneNotSupportedException
    {
      NameReport localNameReport = (NameReport)super.clone();
      localNameReport.report = ((Report)this.report.clone());
      return localNameReport;
    }

    NameReport(String paramString, Report paramReport, AbstractFineBook.1 param1)
    {
      this(paramString, paramReport);
    }

    static String access$100(NameReport paramNameReport)
    {
      return paramNameReport.name;
    }

    static String access$102(NameReport paramNameReport, String paramString)
    {
      return (paramNameReport.name = paramString);
    }

    static Report access$200(NameReport paramNameReport)
    {
      return paramNameReport.report;
    }

    static Report access$202(NameReport paramNameReport, Report paramReport)
    {
      return (paramNameReport.report = paramReport);
    }
  }
}